import { apiBaseUrl, imgBaseUrl, defaultImg} from "../../../utils/config";
import {promiseRequest } from "../../../utils/index";
const app = getApp();
Page({
data: {
  actshareinfo:{},
  ljtj:'',
  imgList:[],
  imgBaseUrl: imgBaseUrl,
  isshare:false,
  backImg:'',
  shareTitle:''
},
onShareAppMessage() {
  return {
    title: this.data.shareTitle,
    path: '/pages/compent/shareHelp/shareHelp?actId=' + this.data.actshareinfo.id,
    imageUrl: this.data.backImg
  }
},
//获取缓存中存储的活动信息
onLoad(options) {
let actId = options.actId;
this.getactshareinfo(actId);
},
onShow(){
},
getactshareinfo(actId){
  let requestObj = {
    url: '/wxa/actshare/getcacheShareById',
    method: 'post',
    dataobj: { actId: actId },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      let actshareinfo = res.data;
      let rewardDetail = actshareinfo.rewardDetail;
      rewardDetail = rewardDetail.split(",");
      rewardDetail = rewardDetail == "" ? [] : rewardDetail;
      let backImg = '';
      if (actshareinfo.backImg == '' || actshareinfo.backImg == null) {
        backImg = defaultImg
      } else {
        backImg = imgBaseUrl + "/" + actshareinfo.backImg
      }
      this.setData({
        actshareinfo: actshareinfo,
        imgList: rewardDetail,
        backImg: backImg,
        shareTitle: "免费领取" + actshareinfo.rewardName + "(价值:" + actshareinfo.rewardPrice + "元)"
      })
      //助力个数
      let helpNumber = actshareinfo.helpNumber ? actshareinfo.helpNumber : 'X';
      if (actshareinfo.helpWayCode == 0) {
        this.setData({
          ljtj: '邀请好友助力达' + helpNumber + '即可领奖',
        })
      } else if (actshareinfo.helpWayCode == 1) {//助力前N名
        this.setData({
          ljtj: '助力排名前' + helpNumber + '即可领奖',
        })
      }
    }
  }).catch((errMsg) => {
  });
},
share(){
  this.setData({
    isshare: true
  })
},
hideModal(){
  this.setData({
    isshare: false
  })
},
jump(e) {
  var page = e.currentTarget.dataset.page;
  wx.navigateTo({
    url: page
  });
}
})